package projectmanagement.web;

import org.springframework.validation.Errors;

import projectmanagement.model.Person;

public class SignInValidator implements
		org.springframework.validation.Validator {
	public boolean supports(Class clazz) {
		return clazz.equals(Person.class);
	}

	/**
	 * Validates an Person command object. Ensures that username is greater
	 * than zero and that a password is specified.
	 * 
	 * @see Person
	 */
	public void validate(Object command, Errors errors) {
		Person person = (Person) command;
		if (person == null)
			return;

		String username = person.getUsername();
		String password = person.getPassword();

		if (username == null || username.trim().length() <= 0) {
			errors.reject("error.login.invalid");
		} else {
			if (password == null || password.trim().length() <=0){
				errors.reject("error.login.invalid");
			}
		}
	}
}
